package net.dengzixu.java.homework.period14.homework4;

/**
 * @author Deng Zixu <admin@dengzixu.com>
 */
public class Account {
    String card;
    String name;
    String address;
    double balance;
    double minBalance;

    /**
     * 账户
     *
     * @param card       账号
     * @param name       储户姓名
     * @param address    地址
     * @param balance    存款余额
     * @param minBalance 最低余额
     */
    public Account(String card, String name, String address, double balance, double minBalance) {
        this.card = card;
        this.name = name;
        this.address = address;
        this.balance = balance;
        this.minBalance = minBalance;
    }

    /**
     * 存款
     *
     * @param num 金额
     */
    public void deposit(double num) {
        // 储存原有金额
        double sBalance = this.balance;

        this.balance += num;

        System.out.printf("[存款] 操作前金额: %f, 操作金额: %f, 操作后金额: %f\n", sBalance, num, this.balance);

    }

    /**
     * 取款
     *
     * @param num 金额
     */
    public void draw(double num) {
        if (this.balance - num < this.minBalance) {
            System.out.println("[取款] 操作失败，金额小于最小金额");
            return;
        }

        // 储存原有金额
        double sBalance = this.balance;

        this.balance -= num;

        System.out.printf("[取款] 操作前金额: %f, 操作金额: %f, 操作后金额: %f\n", sBalance, num, this.balance);

    }

    /**
     * 查询
     */
    public void query() {
        System.out.printf("[查询] 账号: %s, 姓名: %s, 地址: %s, 余额: %f, 最低余额: %f", this.card, this.name,
                this.address, this.balance, this.minBalance);
    }
}
